package com.orcamento.entity.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.joda.time.DateTime;

import com.orcamento.util.AppConfig;
import com.orcamento.util.CalendarUtil;

public class Download {

	private static final String DEFAULT_NAME = "EXPORT-";
	private static final String DEFAULT_EXTENSION = ".csv";
	
	private String filepath;
	private String filename;
	
	public Download(String content, String fundName) throws Exception {
		String path = AppConfig.getDownloadPath();
		String formattedDate = CalendarUtil.toString(new DateTime(), "dd-MM-yy&HH-mm-SS");
		this.filename = DEFAULT_NAME + fundName + "-" + formattedDate + DEFAULT_EXTENSION; 
		this.filepath = path + filename;
		
		FileUtils.writeStringToFile( new File(filepath), content );
	}
	
	public InputStream getStream() throws Exception {
		return new FileInputStream(filepath);
	}

	public String getFilename() {
		return filename;
	}
	
}
